<script>

    var map;
    $(document).ready(function() {

        map = new GMaps({
            div: '#map_canvas',
            lat: <?= $initLat ?>,
            lng: <?= $initLong ?>,
            zoom: 7
        });
<?php if (isset($users)) { ?>
            var locations = [
    <?php
    $end = count($users);
    $i = 0;
    foreach ($users as $k => $item):
        ?>
                {"Nome" : "<?= $item['Nome'] ?>", "lat" : "<?= $item['lat'] ?>", "long" : "<?= $item['long'] ?>"}
        <?php if (++$i != $end) { ?>
                    ,<?php } ?><?php endforeach; ?>
            ];
                    for (i = 0; i < locations.length; i++) {
                map.addMarker({
                    lat: locations[i]["lat"],
                    lng: locations[i]["long"],
                    title: 'locations[i]["Nome"]',
                    infoWindow: {
                        content: locations[i]["Nome"]
                    }
                });
            }
<?php } ?>
<?php if (isset($veterinari)) { ?>
            var locationsVet = [
    <?php
    $ends = count($veterinari);
    $is = 0;
    foreach ($veterinari as $k => $item):
        ?>
                {"Nome" : "<?= $item['NomeVeterinario'] ?>", "lat" : "<?= $item['lat'] ?>", "long" : "<?= $item['long'] ?>"}
        <?php if (++$is != $ends) { ?>
                    ,<?php } ?><?php endforeach; ?>
            ];
                    var icon = new google.maps.MarkerImage("<?= base_url() ?>images/Hb.png", null, null, null, new google.maps.Size(30, 30));
            for (i = 0; i < locationsVet.length; i++) {
                map.addMarker({
                    lat: locationsVet[i]["lat"],
                    lng: locationsVet[i]["long"],
                    title: 'Veterinario ' + locationsVet[i]["Nome"],
                    icon: icon,
                    infoWindow: {
                        content: locationsVet[i]["Nome"]
                    }
                });
            }
<?php } ?>



    });

</script>
<div id="content_ricerca">
    <!-- Page Heading -->
    <section class="page-heading">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h1>Ricerca</h1>
                </div>
                <div class="col-md-6">
                    <ul class="breadcrumb">
                        <li><a href="<?= base_url() ?>">Home</a></li>
                        <li class="active"><a href="<?= base_url() ?>/welcome/ricerca">Ricerca</a></li>

                    </ul>
                </div>
            </div>
        </div>
    </section>
    <!-- Page Heading / End -->
    <section class="page-content">
        <div class="container">
            <!-- Google Map -->
            <div class="googlemap-wrapper">
                <div id="map_canvas" class="map-canvas"></div>
                <div id="content-window" ></div>
            </div>


            <!-- Google Map / End -->
            <?php if (isset($users) && isset($item['CostoGiornaliero'])) { ?>
                <div class="clearfix" style="text-align: center; margin-bottom: -2%;margin-top: 1%;">
                    <!-- Project Feed Filter -->
                    <ul class="project-feed-filter">
                        <li><a href="#" class="btn btn-sm btn-default btn-primary" data-filter="*">Tutti</a></li>
                        <li><a href="#" class="btn btn-sm btn-default" data-filter=".lessTen">Fra 1€ e 10€</a></li>
                        <li><a href="#" class="btn btn-sm btn-default" data-filter=".lessFft">Fra 10€ e 15€</a></li>
                        <li><a href="#" class="btn btn-sm btn-default" data-filter=".fftTwent">Fra 15€ e 20€</a></li>
                        <li><a href="#" class="btn btn-sm btn-default" data-filter=".moreTtwnt">Più di 20€</a></li>
                    </ul>
                    <!-- Project Feed Filter / End -->
                </div>
            <?php } ?>
            <div class="job_listings">
                <form class="job_filters" method="POST" action="<?php echo site_url('welcome/ricerca_ajax'); ?>"> 

                    <div class="search_jobs">
                        <div class="search_keywords">
                            <label for="Indirizzo">Indirizzo</label>
                            <input type="text" name="Indirizzo" id="Indirizzo" placeholder="Indirizzo" class="form-control" value="" />
                        </div>

                        <div class="search_location">
                            <label for="Citta">Città</label>
                            <input type="text" name="Citta" id="Citta" placeholder="Città" class="form-control" value="" />
                        </div>

                        <div class="search_location">
                            <select class="form-control" id="servizio" name="servizio">
                                <option value="1">Dog Sitter</option>
                                <option value="2">Veterinari</option>
                                <option value="3">House Sitter</option>
                                <option value="4">Pet Owner</option>
                            </select>
                        </div>

                        <div class="search_submit">
                            <label>Submit</label>
                            <button id="submit" class="btn btn-block btn-primary">Search</button>
                        </div>
                    </div>
                </form>

                <div class="project-feed project-feed__3cols row" style="padding:1px;">

                    <?php
                    if (isset($users) ) {
                        
                        foreach ($users as $item):
                            ?>
                            <?php
                            if(isset($item['CostoGiornaliero'])){
                                if ($item['CostoGiornaliero'] > 20) {
                                    echo "<div class='col-sm-6 col-md-3 project-item moreTtwnt logo'>";
                                } elseif ($item['CostoGiornaliero'] > 15 && $item['CostoGiornaliero'] <= 20) {
                                    echo "<div class='col-sm-6 col-md-3 project-item fftTwent logo'>";
                                } elseif ($item['CostoGiornaliero'] >= 10 && $item['CostoGiornaliero'] <= 15) {
                                    echo "<div class='col-sm-6 col-md-3 project-item lessFft logo'>";
                                } else {
                                    echo "<div class='col-sm-6 col-md-3 project-item lessTen logo'>";
                                }
                            }else{
                                echo "<div class='col-sm-6 col-md-3 project-item logo'>";
                            }
                            ?>
                            
                            <div class="project-item-inner">
                                <figure class="alignnone project-img">
                                    <img src="<?= base_url() ?><?= $item['path_profile'] ?>" alt="<?= $item['alt_profile'] ?>" />
                                    <div class="overlay">
                                        <?php if(isset($item['CostoGiornaliero'])){ ?>
                                        <a href="<?= base_url() ?>profilo/petsitter/<?= $item['Id'] ?>" class="dlink"><i class="fa fa-link"></i></a>
                                        <?php }else{ ?>
                                        <a href="<?= base_url() ?>profilo/petowner/<?= $item['Id'] ?>" class="dlink"><i class="fa fa-link"></i></a>
                                        <?php } ?>
                                        <a href="<?= base_url() ?><?= $item['path_profile'] ?>" class="popup-link zoom"><i class="fa fa-search"></i></a>
                                    </div>
                                </figure>
                                <div class="project-desc">
                                    <h4><?= $item['Nome'] ?>&nbsp;<?= $item['Cognome'] ?></h4>
                                    <?php if(isset($item['CostoGiornaliero'])): ?>
                                    <h5 class="title"><i class="fa fa-money"></i>Costo Giornaliero : <strong><?= $item['CostoGiornaliero'] ?>€</strong></h5>
                                    <h5 class="desc"><i class="fa fa-money"></i>Costo Orario : <strong><?= $item['CostoOrario'] ?>€</strong></h5>
                                    <?php endif; ?>
                                    <h5> <i class="fa fa-map-marker"></i> <?= $item['Indirizzo'] ?>, <?= $item['Citta'] ?></h5>
                                </div>
                            </div>
                        </div>

                        <?php
                    endforeach;
                }
                ?>
                <?php
                if (isset($veterinari)) {
                    foreach ($veterinari as $item):
                        ?>
                        <div class='col-sm-6 col-md-3 project-item logo'>
                            <div class="project-item-inner">
                                <figure class="alignnone project-img">
                                    <img src="<?= base_url() ?>images/zampa.png" alt="<?= $item['NomeVeterinario'] ?>" />
                                    <div class="overlay">
                                        <a href="#" class="dlink"><i class="fa fa-link"></i></a>
                                        <a href="#" class="popup-link zoom"><i class="fa fa-search"></i></a>
                                    </div>
                                </figure>
                                <div class="project-desc">
                                    <h5 class="title"><?= $item['NomeVeterinario'] ?></strong></h5>

                                </div>
                            </div>
                        </div>

                        <?php
                    endforeach;
                }
                ?>




            </div>
    </section>
</div>
